if(SYSTEMD_FOUND)
    configure_file(ddm.service.in ddm.service)
    install(FILES "${CMAKE_CURRENT_BINARY_DIR}/ddm.service" DESTINATION "${SYSTEMD_SYSTEM_UNIT_DIR}")

    configure_file(ddm-sysuser.conf.in ddm-sysuser.conf)
    install(FILES "${CMAKE_CURRENT_BINARY_DIR}/ddm-sysuser.conf" DESTINATION "${SYSTEMD_SYSUSERS_DIR}" RENAME dde.conf)
endif()

# systemd-tmpfiles can be used standalone without other systemd parts
if(DEFINED SYSTEMD_TMPFILES_DIR)
    configure_file(ddm-tmpfiles.conf.in ddm-tmpfiles.conf)
    install(FILES "${CMAKE_CURRENT_BINARY_DIR}/ddm-tmpfiles.conf" DESTINATION "${SYSTEMD_TMPFILES_DIR}" RENAME ddm.conf)
endif()

if(USE_ELOGIND)
    set(LOGIND_PAM_MODULE "pam_elogind.so")
else()
    set(LOGIND_PAM_MODULE "pam_systemd.so")
endif()
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/ddm-greeter.pam.in" "${CMAKE_CURRENT_BINARY_DIR}/ddm-greeter.pam")

if(EXISTS "/etc/debian_version")
    install(FILES debian.ddm-autologin.pam DESTINATION ${CMAKE_INSTALL_FULL_SYSCONFDIR}/pam.d RENAME ddm-autologin)
    install(FILES debian.ddm-greeter.pam DESTINATION ${CMAKE_INSTALL_FULL_SYSCONFDIR}/pam.d RENAME ddm-greeter)
    install(FILES debian.ddm.pam DESTINATION ${CMAKE_INSTALL_FULL_SYSCONFDIR}/pam.d RENAME ddm)
else()
    if(HAVE_PAM_FAILLOCK)
        install(FILES ddm-autologin.pam DESTINATION ${CMAKE_INSTALL_FULL_SYSCONFDIR}/pam.d RENAME ddm-autologin)
    else()
        install(FILES ddm-autologin-tally2.pam DESTINATION ${CMAKE_INSTALL_FULL_SYSCONFDIR}/pam.d RENAME ddm-autologin)
    endif()

    install(FILES ddm.pam DESTINATION ${CMAKE_INSTALL_FULL_SYSCONFDIR}/pam.d RENAME ddm)
    install(FILES "${CMAKE_CURRENT_BINARY_DIR}/ddm-greeter.pam" DESTINATION ${CMAKE_INSTALL_FULL_SYSCONFDIR}/pam.d RENAME ddm-greeter)
endif()
